<h5>Interfacing the Wiring hardware and Blender/Phyton</h5>
<p>This tutorial introduces the basic interfacing between the Wiring hardware and Blender/Phyton <a href="http://www.blender.org/">http://www.blender.org/</a>. The brief for the tutorial will be to read simple values from the Wiring board. It assumes the Wiring software and Blender/Phyton are installed and the proper Wiring setup has been previously completed. For more Information on Wiring install check out the <a href="http://wiring.org.co/learning/tutorials/">tutorials</a> about Wiring installation and software setup.</p>
<p>This tutorial is based on the tutorial made by Simon Blackmore wich can be found it <a href="http://www.simonblackmore.net/notes/doku.php?id=wiring_to_blender">here</a></p>
<p>Note: This tutorial have been proved it using Blender 2.49 which can be downloaded from <a href="http://download.blender.org/release/">here</a> and Phyton 2.5 wich can be downloaded from <a href="http://www.python.org/download/releases/2.5.6/">here</a>.</p>
<h5>Step 1</h5>
<p>Copy and paste the following code on the Wiring editor: Verify your program is free of compiling errors by pressing the Compile/Verify button in the menu bar. Press the Upload button in the menu bar. In case of syntax errors the Wiring environment will print the error messages otherwise it will print the Upload was completed successfully, the uploading process triggers activity in the Rx/Tx LEDs on the Wiring hardware. The new program will start automatically after uploading. Use the Serial Monitor button to watch the data coming from the Wiring board, then close the Serial Monitor again.</p>
<pre>
/** 
 * Photoresistor / Blender/Python

 * 
 * Reads values from a photoresistor connected to the 
 * analog input pin 0. The value read from the sensor is proportional
 * to the amount of light that hits the sensor surface.
 * The value read is printed through the serial to be monitored
 * in the console or received on Blender
 */

int val; 

void setup()
{
  Serial.begin(9600);      // sets the serial port to 9600
}

void loop() 
{
  val = analogRead(0);     // read analog input pin 0
  Serial.println(val/4, BYTE);  // prints the value read from the
                               // sensor in analog pin 0 divided by 4 (range 0-255)
  delay(200);                  // wait 200ms for next reading
}
</pre>
<p>&nbsp;</p>
<h5>Paso 2</h5>
<p>Download PySerial <a href="http://pyserial.sourceforge.net/">here</a>. Uncompress the file and placed the folder &quot;serial&quot; with the other Python libraries for Blender.</p>
<h5>Step 3</h5>
<p>Next step is to setup things in Blender. Setup the interface to &quot;Scripting&quot; mode. </p>
<p><img src="imgs/blender-01.png" width="700" height="423" /></p>
<p>&nbsp;</p>
<h5>Step 4</h5>
<p>Copy the following code in the editor and name it &quot;script.py&quot;.</p>
<pre>
import serial
# you will need the name of your serial port
# check in wiring - tools - menu
ser = serial.Serial('COM2', 9600)

x = ser.read(size=1)
y = ord(x)
print "y=", y

ser.close()
</pre>
<p><img src="imgs/blender-02.png" width="489" height="316" /></p>
<p>&nbsp;</p>
<h5>Step 5</h5>
<p>Attach an object. Select any object in the scene and click on its logic properties in the &quot;Buttons Window&quot;.</p>
<p>Add an always sensor and link it to the python script. This should mean the python script will be executed when the game engine is running. It should look like this: </p>
<p><img src="imgs/blender-03.png" width="979" height="201" /></p>
<h5>Step 6</h5>
<p>Run the game engine. Click in the '3D Panel' and just press 'P'. The '3D Panel' should now change into the game view and numbers from wiring should appear in the console window.</p>
<img src="imgs/blender-04.png" width="669" height="338" />
<p>Next &gt;&gt; <a href="blender2.html">Sending data to the Wiring board from Blender/Python.</a></p>
